/**
 * Created by Administrator on 2017/4/30.
 */
//时间
function time(){
    var date = new Date();//获取当前日期
    var week;//获取星期
    switch (date.getDay()){
        case 1: week="Monday"; break;
        case 2: week="Tuesday"; break;
        case 3: week="Wednesday"; break;
        case 4: week="Thursday"; break;
        case 5: week="Friday"; break;
        case 6: week="Saturday"; break;
        default:week="Sunday"; break;
    }
    var month;  //获取月份
    switch (date.getMonth()+1){
        case 1: month="January"; break;
        case 2: month="february "; break;
        case 3: month="March "; break;
        case 4: month="April "; break;
        case 5: month="May "; break;
        case 6: month="June "; break;
        case 7: month="July "; break;
        case 8: month="August"; break;
        case 9: month="September"; break;
        case 10: month="October "; break;
        case 11: month="November"; break;
        case 12: month="December"; break;
    }
    var year = date.getFullYear();//获取年份
    var day = date.getDate();//获取当天的日
    if(day<10)
        day= "0"+day;
    var hours =date.getHours();//获取小时
    if(hours<10)
        hours= "0"+hours;
    var minutes =date.getMinutes();//获取分
    if(minutes<10)
        minutes= "0"+minutes;
    var day =day+" "+month+","+week;
    var H=hours;
    var M=minutes;
    document.getElementById("YY").innerHTML= year;
    document.getElementById("day").innerHTML= day;
    document.getElementById("H").innerHTML= H;
    document.getElementById("M").innerHTML= M;
}
//设置1秒调用一次show_cur_times函数
setInterval("time()",100);

define('Login', ['avalon', 'text!../../package/Login/Login.html',
    'css!../../package/Login/Login.css',
    '../../lib/tip/tip.js'],
    function (avalon, html, css) {
    var vm = avalon.define({
        $id: "Login",
        ready: function (i) {
            index.html=html

            avalon.scan()
        },

        //切换
        Logind:true,
        zhuce:function () {
           vm. Logind=false
        },
        denglu:function () {
            vm. Logind=true
        },
        //自动登录
        yhm:cache.go("Account"),
        m:cache.go("PWD"),
        reLogin:function () {
            var SID={
                Account:vm.yhm,
                PWD:vm.m
            }
            require(["../../obj/User"],function (obj) {
                obj.reLogin(SID,function (res) {
                    goto('#!/Home/0')
                },function (err) {
                    tip.on(err)
                })
            })
        },
        Account:"",
        PWD:"",
        Login:function () {
            if (vm.Account.length<6){
                tip.on("用户名为空或者小于6位",0,1000)
            }
            if (vm.PWD.length<6){
                tip.on("密码为空或者小于6位",0,1000)
            }
            require(['../../obj/User'],function (obj) {
                obj.login(vm.Account,vm.PWD,function (res) {
                    goto('#!/Home/0')
                },function (err) {
                    tip.on(err)
                })
            })
        },
        //跳转修改密码页面
        resetPWD:function () {
            goto('#!/resetPWD/0')
        },

        ZAccount:"",
        mm:"",
        zpwd:"",
        Email:"",
        reg:function () {
            var Properties = {
                Email:vm.Email
            }
            if (vm.ZAccount.length<6){
                tip.on("用户名少于6位或者为空",0,2000)
            }else{
                if(vm.mm.length<6){
                    tip.on("密码少于6位或者为空",0,2000)
                }
                else{
                    if(vm.mm=vm.zpwd){
                        if(vm.Email.length<1){
                            tip.on("邮箱不能为空",0,2000)
                        }else {

                            require(['../../obj/User'],function (obj) {
                                obj.reg(vm.ZAccount,vm.mm,Properties,function (res) {
                                    tip.on("注册成功",1,1000)
                                    vm.ZAccount=""
                                    vm.mm=""
                                    vm.zpwd=""
                                    vm.Email=""
                                },function (err) {
                                    tip.on(err)
                                })
                            })
                        }
                    }else {
                        tip.on("两次密码不相同",0,2000)
                    }
                }
            }


        }

    })
        return window[vm.$id]=vm
})